home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / pyshared / GdmGreeter / rootaccess.py < prev    next >
Encoding:
Python Source  |  2013-01-10  |  1.9 KB  |  58 lines

  1. #!/usr/bin/python
  2. #
  3. # Copyright 2012 Tails developers <tails@boum.org>
  4. # Copyright 2011 Max <govnototalitarizm@gmail.com>
  5. # Copyright 2011 Martin Owens
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. #  it under the terms of the GNU General Public License as published by
  9. #  the Free Software Foundation, either version 3 of the License, or
  10. #  (at your option) any later version.
  11. #
  12. #  This program is distributed in the hope that it will be useful,
  13. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  15. #  GNU General Public License for more details.
  16. #
  17. #  You should have received a copy of the GNU General Public License
  18. #  along with this program.  If not, see <http://www.gnu.org/licenses/>
  19. #
  20. """Root access handling
  21.  
  22. """
  23. import os
  24. import logging
  25. import pipes
  26.  
  27. import GdmGreeter.config
  28.  
  29. class RootAccessSettings(object):
  30.     """Model storing settings related to root access
  31.  
  32.     """
  33.     def __init__(self):
  34.         # Root password
  35.         self.password = None
  36.         # XXX: this should read the content of the setting file
  37.  
  38.     @property
  39.     def password(self):
  40.         return self._password
  41.  
  42.     @password.setter
  43.     def password(self, password):
  44.         self._password = password
  45.         if password:
  46.             with open(GdmGreeter.config.rootpassword_output_path, 'w') as f:
  47.                 os.chmod(GdmGreeter.config.rootpassword_output_path, 0o600)
  48.                 f.write('TAILS_USER_PASSWORD=%s\n' % pipes.quote(self.password))
  49.                 logging.debug('password written to %s',
  50.                               GdmGreeter.config.rootpassword_output_path)
  51.         else:
  52.             try:
  53.                 os.unlink(GdmGreeter.config.rootpassword_output_path)
  54.                 logging.debug('removed %s', GdmGreeter.config.rootpassword_output_path)
  55.             except OSError:
  56.                 # configuration file does not exist
  57.                 pass
  58.